package ext.opensource.netty.common;

import io.netty.channel.Channel;
import io.netty.util.Attribute;

public class NettyUtil {
	public static String getClientId(final Channel channel) {
		final Attribute<String> attr = channel.attr(NettyConstant.CLIENTID_KEY);
		return attr.get();
	}

	public static void setClientId(final Channel channel, final String clientId) {
		final Attribute<String> attr = channel.attr(NettyConstant.CLIENTID_KEY);
		attr.set(clientId);
	}

	public static boolean isLogin(final Channel channel) {
		final String clientId = channel.attr(NettyConstant.CLIENTID_KEY).get();
		return clientId != null && clientId.trim().length() > 0;
	}
}
